package com.abc.files;

import java.io.File;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

import org.apache.commons.io.FileUtils;
import org.apache.commons.io.filefilter.FileFilterUtils;
import org.apache.commons.io.filefilter.TrueFileFilter;

public class FileFinder {

	List<FileRecord> recordList;
	String directory;
	
	public FileFinder(String directory) {
		
		this.directory = directory;
		try {

			recordList = new ArrayList<FileRecord>();
			Collection<File> files = FileUtils.listFiles(
					FileUtils.getFile(directory),
					FileFilterUtils.suffixFileFilter(".xlxs"),
					TrueFileFilter.INSTANCE);
			files.addAll(FileUtils.listFiles(FileUtils.getFile(directory),
					FileFilterUtils.suffixFileFilter(".xls"),
					TrueFileFilter.INSTANCE));
			for (File it : files) {
				String[] Path = it.getPath().split("\\\\");
				String[] filename = it.getName().split("\\.");
				recordList.add(new FileRecord(Path[1], Path[2],filename[0], it));
			}
		} catch (Exception e) {
			System.err.println(e);
		}
	}

	public static void main(String[] args) {
		FileFinder ff = new FileFinder("Dane_testowe");
		System.out.println(ff.getRecords().size());
	}

	public List<FileRecord> getRecords() {
		return recordList;
	}

}
